<?php

include '../../../configuration.php';

$smarty->template_dir = LOCAL_PATH.'administrator/main/templates/';
$smarty->compile_dir = LOCAL_PATH.'administrator/main/templates_c/';
$smarty->config_dir = LOCAL_PATH.'administrator/main/configs';

$smarty->compile_check = true;
//$smarty->debugging = true;

if (isset($_POST['new_group'])){
	$new_group = $_POST['new_group'];
	$new_faculty = $_POST['faculty'];
	$id = $_POST['id'];
	mysql_query("UPDATE `groups` SET group_name = '$new_group', faculty_id = $new_faculty WHERE group_id = $id");
	header("Location: modify_or_delete_group.php");
}
else if(isset($_GET['id'])){
	$id = $_GET['id'];
}else{
	header("Location: modify_or_delete_group.php");
}

$result = mysql_query("SELECT * FROM `groups` WHERE group_id = $id");
$row = mysql_fetch_assoc($result);
$group = $row["group_name"];
$faculty_id = $row["faculty_id"];

$faculty_names = array();
$faculty_ids = array();
$result2 = mysql_query("SELECT * FROM `faculties`");
while($rows2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
	$faculty_names[] = $rows2["faculty_name"];
	$faculty_ids[] = $rows2["faculty_id"];
}

$smarty->assign('faculty_id',$faculty_id);
$smarty->assign('faculty_ids',$faculty_ids);
$smarty->assign('faculty_names',$faculty_names);
$smarty->assign('id',$id);
$smarty->assign('group_name',$group_name);

include '../../check.php';
if ($checking == 1)
	$smarty->display('modifing_group.tpl');
else echo "You are not autorised"; exit;

?>